package com.shihb.chapter03oop

/**
 * Description:
 *
 * @author shihb
 * @date 2020/9/30 17:25
 */
object Demo12CaseClass {
  def main(args: Array[String]): Unit = {
    // 该案例的作用就是样例类在模式匹配的优劣性
    for(ele <- Array(Dollar(1000.0),Currency(1000.0,"RMB"),NoAmount)){
      val result=ele match {
        case Dollar(v)=>v
        case Currency(x,y)=>(x,y)
        case NoAmount=> ""
      }
      println("res:"+result)
    }

  }
}
abstract class Amount
case class Dollar(value:Double) extends Amount
case class Currency(value:Double,unit:String) extends Amount
case object NoAmount extends Amount
